package lanbo.cj.lmp.utils;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.tech.MifareClassic;
import android.nfc.tech.NfcA;
import android.os.Parcelable;
import android.widget.Toast;

public class NFCUtils {
	private NfcAdapter nfcAdapter;
	private PendingIntent pendingIntent;
	private IntentFilter[] mFilters;
	private String[][] mTechLists;
	private boolean isFirst = true;
	
	
	private String readTag(Activity mActivity, String tag) {
		nfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);
		if (nfcAdapter == null) {
			Toast.makeText(mActivity, "该设备不支持NFC", Toast.LENGTH_SHORT).show();
			mActivity.finish();
			return null;
		} else if (!nfcAdapter.isEnabled()) {
			Toast.makeText(mActivity,"请打开NFC功能", Toast.LENGTH_SHORT).show();
			mActivity.finish();
			return null;
		}
		IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
		ndef.addCategory("*/*");
		mFilters = new IntentFilter[] { ndef };// 过滤器
		mTechLists = new String[][] { new String[] { MifareClassic.class.getName() },
				new String[] { NfcA.class.getName() } };// 允许扫描的标签类型
		return null;
	}
	
	private String processIntent(Intent intent) {
		Parcelable[] rawmsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
		NdefMessage msg = (NdefMessage) rawmsgs[0];
		NdefRecord[] records = msg.getRecords();
		String resultStr = new String(records[0].getPayload());
		return resultStr;
	}
}
